package cn.elead.chaos.remote.web.remote.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.framework.web.global.response.UnifiedReturn;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.sso.core.util.SsoUtils;
import cn.elead.chaos.remote.web.remote.domain.SysUser;
import cn.elead.chaos.remote.web.remote.service.ISysUserService;

/**
 * 个人信息 业务处理
 * 
 * @author luopeng
 */
@UnifiedReturn
@RestController
@RequestMapping("/system/user/profile")
public class RemoteProfileController extends BaseController {

	@Autowired
	private ISysUserService userService;

	/**
	 * 个人信息
	 */
	@GetMapping
	public Map<String, Object> profile() {
		SysUser user = userService.selectUserById(SsoUtils.getUserId());
		Map<String, Object> ajax = new HashMap<String, Object>();
		ajax.put("user", user);
		ajax.put("roleGroup", userService.selectUserRoleGroup(user.getLoginName()));
		ajax.put("postGroup", userService.selectUserPostGroup(user.getUserName()));
		return ajax;
	}

	/**
	 * 修改用户
	 */
	@PutMapping
	@Log(title = "个人信息", businessType = BusinessType.UPDATE)
	public int updateProfile(@RequestBody SysUser user) {
		return userService.updateUserProfile(user);
	}
}
